This example consists of the following source files, located in the src directory:
The example demonstrates using the Multi-file Interprocedural Optimization (IPO) feature of the Intel® Fortran compiler. When this option is enabled, each source file is first compiled to an intermediate representation. Then, when the application is linked, the compiler is called again to bring together all of the intermediate representation and optimize it as a whole. This allows the optimizer to make better choices of generated code and to inline smaller procedures.
In this program, there are three small procedures and a main program across three source files. With IPO, it as if all three files were compiled from a single source file and extensive optimization is possible. Here, the subroutine and two functions are completely inlined into the main program, exposing more optimization opportunities and eliminating call overhead.
To see the effect of IPO it is best to view the optimization report. If you are using the Microsoft Visual Studio* solution provided for Windows*, the project is set to do this automatically. Just build the solution and then open the source file ipo_sample_main.f90
. Embedded in the source display will be notes about optimizations performed, including inlining. You can also click on the Compiler Inline Report or Compiler Optimization Report tabs to see additional information.
If building from the command line, you can open the optimization report in a text editor. The build script or makefile places the report in ipo_sample.optrpt
. Note that the build script and makefile specifies the IPO option (/Qipo
or -ipo
) on both the compile and the link step and that the ifort
command must be used for linking as this adds the pre-link optimization phase. The options for the optimization report need be on the link step only.
The optimization report indicates the procedures that are inlined and that the now-unneeded ("dead") procedures are deleted from the code.
To build from the command line on Windows, use build.bat
. Arguments are 'build' or 'clean' - the default is 'build'. On Linux* or macOS*, use make to compile and link. After the build completes, open ipo_sample.optrpt
in a text editor. Use the command ./ipo_sample.out to run the program.